package com.flame.user.service;

import java.util.List;

import com.flame.user.controller.vo.DataAuthVo;
import com.flame.user.entity.DataAuth;
import com.flame.user.exception.DataAuthExceptionMessage;
import com.flame.user.exception.DataAuthRuntimeException;
import com.flame.user.mapper.DataAuthMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * flame_data_auth 数据权限表
 *
 * @author 吴欣童
 * @since 2023-02-10 10:18:15
 */
@Service
public class DataAuthService {

    @Autowired
    private DataAuthMapper dataAuthMapper;

    public List<DataAuth> pageDataAuth(DataAuthVo dataAuthVo) {
        return dataAuthMapper.page(dataAuthVo);
    }

    public void maintainDataAuth(DataAuth dataAuth) {
        DataAuth dbDataAuth = dataAuthMapper
            .selectById(dataAuth.getObjId(), dataAuth.getObjType(), dataAuth.getDataType(), dataAuth.getDataObjCode());
        if (dbDataAuth != null) {
            dataAuthMapper.updateById(dataAuth);
        } else {
            dataAuthMapper.insert(dataAuth);
        }
    }

    public void deleteDataAuth(DataAuth dataAuth) {
        dataAuthMapper
            .deleteById(dataAuth.getObjId(), dataAuth.getObjType(), dataAuth.getDataType(), dataAuth.getDataObjCode());
    }
}
